package firm;

import java.util.Random;

public class Addition_Machine {

	private int MachineID;
	private Task task;
	private boolean isRepairing = false;
	private boolean isBroken = false;
	
	public  Addition_Machine(int ID){
		this.MachineID = ID;
	}
	
	public boolean is_Repairing(){
		return isRepairing;
	}
	
	public void Repair(){
		this.isRepairing=false;
	}
	
	public int getID(){
		return MachineID;
	}
	
	public float random(){
		Random r = new Random();
		float result = r.nextFloat();
		return result;
	}
	
	
	public Task start_Machine(Task task){
		this.task = task;
		System.out.println("Addition machine nr " + MachineID + " starts.");
		int x=0, y=0, result=2000000;
		x = task.arg1;
		y = task.arg2;
		task.result = result;
		if(random()<GlobalData.PROBABILITY_OF_BROKE){
			if(task.operation=="+") result = x + y;
			else result = x - y;
			task.result = result;
			//System.out.println("Addition machine nr " + MachineID + " returned: " + task.result);
		}
		else{
			isRepairing = true;
			System.out.println("Addition machine nr " + MachineID + " is broken!!! Returning the task...");
		}
		return task;
	}
	
}
